package com.example.base_kotlin_xml

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.base_kotlin_xml.view.HeartbeatMonitorFragment
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
 * @Author: jiangKunKun
 * @CreateDate: 2025/10/17
 * @Description:
 * @SpittingGrooves:
 */
@RunWith(AndroidJUnit4::class)
class MainActivityTest {

    @get:Rule
    val activityRule = ActivityScenarioRule(HeartbeatMonitorFragment::class.java)

    @Test
    fun testSendHeartButtonExists() {
        // 测试发送心跳按钮是否存在
        onView(withId(R.id.btn_send_heart))
            .check(matches(withText("发送心跳")))
    }

    @Test
    fun testGetHeartButtonExists() {
        // 测试获取心跳值按钮是否存在
        onView(withId(R.id.btn_get_heart))
            .check(matches(withText("获取心跳值")))
    }

    @Test
    fun testSendMsgButtonExists() {
        // 测试发送消息按钮是否存在
        onView(withId(R.id.btn_send_msg))
            .check(matches(withText("发送消息")))
    }

    @Test
    fun testReceivedMsgButtonExists() {
        // 测试模拟收到消息按钮是否存在
        onView(withId(R.id.btn_received_msg))
            .check(matches(withText("模拟收到消息取消超时")))
    }

    @Test
    fun testButtonClickResponses() {
        // 测试点击发送心跳按钮
        onView(withId(R.id.btn_send_heart))
            .perform(click())

        // 测试点击获取心跳值按钮
        onView(withId(R.id.btn_get_heart))
            .perform(click())

        // 测试点击发送消息按钮
        onView(withId(R.id.btn_send_msg))
            .perform(click())

        // 测试点击模拟收到消息按钮
        onView(withId(R.id.btn_received_msg))
            .perform(click())
    }
}